package com.jh.jingfei.home;

import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.jh.jingfei.R;
import com.jh.jingfei.home.adapter.ParamRvAdapter;
import com.jh.jingfei.widget.MyToolbar;

import me.yokeyword.fragmentation_swipeback.SwipeBackFragment;

/**
 * @author lxb
 * Param List (参数列表)
 */
public class ParamListFragment extends SwipeBackFragment {
    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";

    private String mParam1;
    private String mParam2;
    private MyToolbar param_list_top_toolbar;
    private RecyclerView param_list_rv;
    private ParamRvAdapter paramRvAdapter;

    public ParamListFragment() {
    }

    public static ParamListFragment newInstance(String param1, String param2) {
        ParamListFragment fragment = new ParamListFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        args.putString(ARG_PARAM2, param2);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_param_list, container, false);
        return attachToSwipeBack(view);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        param_list_top_toolbar = view.findViewById(R.id.param_list_top_toolbar);
        param_list_top_toolbar.setTitle("参数列表");
        param_list_rv = view.findViewById(R.id.param_list_rv);
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        setParallaxOffset(0.5f);

        param_list_top_toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                _mActivity.onBackPressed();
            }
        });

        param_list_rv.setLayoutManager(new LinearLayoutManager(getContext()));
        paramRvAdapter = new ParamRvAdapter(getContext());
        param_list_rv.setAdapter(paramRvAdapter);
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
    }

    @Override
    public void onDetach() {
        super.onDetach();
    }
}
